/**
 * Course Project for User Interface Programming I, 2011
 * Group 19
 */
package justdoit.actions;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import justdoit.Startup;
import justdoit.controller.LanguageManager;
import justdoit.model.DefaultSettings;

/**
 * The action to change the view-mode of mainframe
 * toggle between Normal (Table) view and Compact (List) view.
 * @author Can
 */
public class CompactViewAction extends AbstractAction {

    public CompactViewAction() {
        super(LanguageManager.getString("menu.view.compact"));
        putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("F8"));
    }

    public CompactViewAction(String text) {
        super(text);
    }

    public CompactViewAction(String text, ImageIcon icon) {
        super(text, icon);
    }

    public CompactViewAction(String text, ImageIcon icon,
            String desc, Integer mnemonic) {
        super(text, icon);
        putValue(SHORT_DESCRIPTION, desc);
        putValue(MNEMONIC_KEY, mnemonic);
    }

    public void actionPerformed(ActionEvent e) {
        String mode = Startup.getDs().getMode();
        if (mode.equals(DefaultSettings.MODE_NORMAL)) {
            Startup.getMainFrame().compactView();
            ((JMenuItem)e.getSource()).setText(LanguageManager.getString("menu.view.normal"));
        } else {
            Startup.getMainFrame().normalView();
            ((JMenuItem)e.getSource()).setText(LanguageManager.getString("menu.view.compact"));
        }
    }
}
